package cn.tedu.tickets;

import java.util.Arrays;

/*本类模拟窗口售票*/
public class TestThread {
    public static void main(String[] args) {
        new TicketThread("窗口一").start();
        new TicketThread("窗口二").start();
        new TicketThread("窗口三").start();
/*        System.out.println("窗口一售出"+TicketThread.j+"张票");
        System.out.println("窗口二售出"+TicketThread.k+"张票");
        System.out.println("窗口三售出"+TicketThread.a+"张票");*/


    }
}

class TicketThread extends Thread {
  static int i = 100;
static int j,k,a,b;
    public TicketThread(String name) {
        super(name);
    }

    public TicketThread() {
    }

    @Override
    public    void run() {


            while (true) {
                synchronized(TicketThread.class){
                if (i > 0) {

                    System.out.println(getName() + "\t第" + i + "张票");
                    --i;

                    if (getName().equals("窗口一")) {
                        j += 1;
                    } else if (getName().equals("窗口二")) {
                        k += 1;
                    } else if(getName().equals("窗口三")) {
                        a += 1;
                        continue;
                    }


                } else {
                    break;
                }
            }
        }
    }
}
